package Controller;

import lombok.extern.slf4j.Slf4j;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Title 类名
 * @Description 类描述
 * @Date 2016/4/27 16:09
 * @Author 梁健康
 * @Version 2.0
 */
@Slf4j
@WebServlet(urlPatterns={"/healthcheck.html"})
public class HealthCheckServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        log.info("test");
        request.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        BufferedInputStream inputStream = new BufferedInputStream(HealthCheckServlet.class.getResourceAsStream("/healthcheck.htm"));
        StringBuilder sb = new StringBuilder();
        byte[] line = new byte[2048];
        while (inputStream.read(line) != -1) {
            sb.append(new String(line));
        }
        response.setContentType("text/html;charset=UTF-8");
        out.println(sb.toString());
    }
}
